package com.aaa.order.controller;

import com.aaa.order.entity.TbAccAddress;
import com.aaa.order.service.impl.TbAccAddressServiceImpl;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("address")
public class TbAddressController {

    @Resource
    TbAccAddressServiceImpl tbAccAddressServiceImpl;

    /*根据用户查全部地址*/
    @RequestMapping("findByTbid")
    public List<TbAccAddress> findByTbid(String accountId){
        return tbAccAddressServiceImpl.findByTbid(accountId);
    }

    @RequestMapping("findById/{tid}")
    public TbAccAddress findById(@PathVariable String tid){
        return tbAccAddressServiceImpl.findById(tid);
    }

    @RequestMapping("saveOrUpdate")
    public boolean saveOrUpdate(TbAccAddress tbAccAddress){
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(date);
        tbAccAddress.setUpdateDate(dateString);

        return tbAccAddressServiceImpl.saveOrUpdate(tbAccAddress);
    }

    @RequestMapping("delete/{tid}")
    public boolean delete(@PathVariable String tid){
        return tbAccAddressServiceImpl.removeById(tid);
    }
}
